package com.zhiqiang.gameserver.thread;

import com.zhiqiang.gameserver.entity.ZQGameServerEntity;
import com.zhiqiang.gameserver.handler.MessageHandler;
import com.zhiqiang.gameserver.handler.UserInfoMessageHandler;
import com.zhiqiang.gameserver.queue.BaseQueue;

import java.util.ArrayList;
import java.util.List;

public class HandleMsgThread extends AbstractThread {


    public HandleMsgThread(BaseQueue<ZQGameServerEntity> INSTANCE) {
        super(INSTANCE);
    }

    private static MessageHandler handler = new UserInfoMessageHandler();

    @Override
    public void handleMsg(ZQGameServerEntity entity) {
        List<ZQGameServerEntity> msgList = new ArrayList<ZQGameServerEntity>();// 用于存放处理后同时发送的几条消息
        try {
            handler.handleMsg(entity, msgList);// 处理消息
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (msgList != null && msgList.size() > 0) {
            for (ZQGameServerEntity message : msgList) {
                    message.getChannel().writeAndFlush(message);// 发送消息

            }
        }
        msgList.clear();
        msgList = null;
    }
}
